package com.guigu.zj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.MotionMapper;
import com.guigu.mapper.SerialcodingMapper;
import com.guigu.pojo.Motion;
import com.guigu.pojo.Serialcoding;
import com.guigu.zj.pojo.MpageVo;
import com.guigu.zj.service.MotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MotionServiceImpl implements MotionService {
    @Autowired
    MotionMapper motionMapper;
    @Autowired
    SerialcodingMapper ser;
    public MpageVo<Motion> queryAll(MpageVo mpageVo) {
        PageHelper.startPage(mpageVo.getPage(),mpageVo.getNum());
        List<Motion> list = motionMapper.queryAll(mpageVo);
        PageInfo pageInfo = new PageInfo(list);
        long total = pageInfo.getTotal();
        MpageVo<Motion> vo= new MpageVo<Motion>();
        vo.setTotal(total);
        vo.setRows(list);
        return vo;

    }

    public int insertSelective(Motion record) {
        Serialcoding serialcoding = ser.find();
        record.setMotion("yd00"+(serialcoding.getMotionencoded()+1));
        Serialcoding s = new Serialcoding();
        s.setMotionencoded(serialcoding.getMotionencoded()+1);
        ser.update(s);
        return motionMapper.insertSelective(record);

    }

    public Motion selectByPrimaryKey(Integer id) {
        return motionMapper.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(Motion record) {
        return motionMapper.updateByPrimaryKeySelective(record);
    }

    public int deleteByPrimaryKey(Integer id) {
        return motionMapper.deleteByPrimaryKey(id);
    }
}
